#ifndef QUATERNION_H
#define QUATERNION_H

#include "Vector3f.h"

namespace XYF
{
    /**
     * @file: Quaternion.h
     * @author: xingyifan
     * @date: 2023-03-11 19:59
     *
     * @description: 四元数
     */

    class Quaternion
    {
    protected:
        Real m_s;
        Vector3f m_v;

    public:
        Quaternion(Real s = 0, Vector3f v = {0, 0, 0});
        Quaternion(Vector3f v, Real theta); // 获得 p 绕轴 v 逆时针旋转 theta 角的四元数 q, (q * p / q)
        Quaternion(Vector3f a, Vector3f b); // 获得从轴 a 转动到轴 b 的四元数，只保证方向相同，不保证转动后长度相同

        Quaternion operator*(Real t) const;
        Quaternion operator/(Real t) const;
        Quaternion operator+(const Quaternion &q) const;
        Quaternion operator-(const Quaternion &q) const;
        Quaternion operator*(const Quaternion &q) const;
        Quaternion operator/(const Quaternion &q) const;
        bool operator==(const Quaternion &q) const;

        Real s() const;
        Vector3f v() const;

        Real &rs();
        Vector3f &rv();

        // 输出函数
        friend std::ostream &operator<<(std::ostream &o, const Quaternion &q)
        {
            o << q.s() << " " << q.v() << std::endl;
            return o;
        }
    };

    Real length(Quaternion q);          // 四元数长度
    Quaternion normalize(Quaternion q); // 四元数规范化
}

#endif // QUATERNION_H
